package com.googlecode.jpocketmod.actions;

import com.googlecode.jpocketmod.DialogManager;
import com.googlecode.jpocketmod.state.AppState;
import com.googlecode.jpocketmod.templates.PocketModTemplate;
import com.googlecode.jpocketmod.templates.pages.PocketModPageInstance;
import java.awt.event.ActionEvent;

/**
 *
 * @author David Sosby
 */
public class ChoosePageAction extends ApplicationAction  {
	private int pageIndex;
	
	public ChoosePageAction(int pageIndex)  {
		this.pageIndex = pageIndex;
	}

	@Override
	protected void runAction() {
		PocketModTemplate loadedTemplate = AppState.getInstance().getCurrentlyLoadedTemplate();
		PocketModPageInstance currentPage = loadedTemplate.getPage(pageIndex);
		PocketModPageInstance editedPage = DialogManager.getInstance().showPageChooserDialog(currentPage);
		
		loadedTemplate.setPage(editedPage, pageIndex);
	}

	public void actionPerformed(ActionEvent e) {
		runAction();
	}
	
}
